#include<iostream>
#include<stack>
using namespace std;

int main()
{
	stack<int>st;
//	int n=20200202;
//	int x=n/10000;//2020
    int n,date;
    cin>>n;
    date=n;
    n/=10000;
    int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
	while(1)
	{
		int x=n+1;
		int k=x;
		while(x){
			st.push(x%10);
			x/=10;
		}
		int day1=st.top();
	    st.pop();
	    int day2=st.top();
	    st.pop();
	    int day=day2*10+day1;
	    
	    int mon1=st.top();
	    st.pop();
	    int mon2=st.top();
	    st.pop();
	    int mon=mon2*10+mon1;
	    
	    if(mon<=12&&mon)
	    {
	        if(day<=month[mon]&&day)
			{
				cout<<k<<mon2<<mon1<<day2<<day1<<endl;
				break;
				}	
		}
	    n++;
	}
	n=date/1000000;
	while(1)
	{
		int x=n+1;
		int k=x;
		while(x){
			st.push(x%10);
			x/=10;
		}
		int day1,day2;
		day1=st.top();
		st.pop();
		day2=st.top();
		st.pop();
		int day=day2*10+day1;
		int mon=day;
	    if(mon<=12&&mon)
	    {
	        if(day<=month[mon]&&day)
			{
				cout<<k<<k<<day2<<day1<<day2<<day1<<endl;
				break;
				}	
		}		
		n++;
	}
	return 0;
 } 
 
 //20211202
 //xxxx  12  31
